<template>
  <div class="contenr">
    <el-form :inline="true" :model="forms" ref="queryForm" class="demo-form-inline">
      <el-form-item label="姓名">
        <el-input v-model="forms.name" size="mini" clearable placeholder="姓名"></el-input>
      </el-form-item>
      <!-- <el-form-item label="学号">
        <el-input v-model="forms.studentId" size="mini" clearable placeholder="学号"></el-input>
      </el-form-item> -->
      <el-form-item label="手机号">
        <el-input v-model="forms.phone" size="mini" clearable placeholder="手机号"></el-input>
      </el-form-item>
      <!-- <el-form-item label="证件号">
        <el-input v-model="forms.certificateId" size="mini" clearable placeholder="证件号"></el-input>
      </el-form-item> -->
      <el-form-item label="班级名称" prop="className">
        <el-input v-model="forms.className" size="mini" clearable placeholder="班级名称"></el-input>

      </el-form-item>
      <el-form-item label="修改照片时间" prop="dateList">
        <el-date-picker
          v-model="forms.dateList"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
        />
      </el-form-item>
      <el-form-item>
        <el-button type="primary" size="mini" icon="el-icon-search" @click="findStudentList">查询</el-button>
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery">重置</el-button>
      </el-form-item>

      </el-form>

      <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button size="mini" type="primary" icon="el-icon-plus"  @click="Add()">
          新增学员
        </el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-circle-check"
          size="mini"
          @click="batchUpdateStatus(1)"
          :disabled="multiple"
          >有效</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-circle-close"
          size="mini"
          @click="batchUpdateStatus(0)"
          :disabled="multiple"
          >无效</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          icon="el-icon-upload2"
          size="mini"
          @click="importData"
          >学员导入</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="exportStudentInfo"
          >学员导出</el-button>

      </el-col>

      <el-col :span="1.5">
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          @click="handleDeleteBatch()"
          :disabled="multiple"
        >删除</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          icon="el-icon-key"
          size="mini"
          @click="batchResetStudentsPwdHander()"
          :disabled="multiple"
        >重置学生密码</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          icon="el-icon-refresh"
          size="mini"
          @click="batchResetParentPwdHander()"
          :disabled="multiple"
        >重置家长密码</el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-success"
          size="mini"
          @click="batchUpdateEnable(1)"
          :disabled="multiple"
        >启用</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-error"
          size="mini"
          @click="batchUpdateEnable(0)"
          :disabled="multiple"
        >停用</el-button>
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          icon="el-icon-download"
          size="mini"
          @click="deviceStudentExcel()"

        >人员设备信息导出</el-button>
      </el-col>


    </el-row>

    <div class="head">
      <el-table :data="tableDataList" style="width: 100%"  v-loading="loading" @selection-change="handleSelectionChange">
        <el-table-column type="selection" width="55" align="center" />
        <el-table-column prop="id" label="学生ID" width="90" align="center" :show-overflow-tooltip="true" fixed sortable>
        </el-table-column>
        <el-table-column prop="name" label="姓名"  width="100" align="center" :show-overflow-tooltip="true" fixed>
          <template slot-scope="scope">
            <el-link icon="el-icon-edit" type="primary" @click="modify(scope.row)">{{scope.row.name}}</el-link>
          </template>
        </el-table-column>
        <el-table-column prop="phone" label="学生手机号" width="120"  align="center" :show-overflow-tooltip="true" fixed sortable>
        </el-table-column>
        <el-table-column prop="guardianPhoneNumber" label="家长手机号" width="120"  align="center" :show-overflow-tooltip="true" fixed sortable>
        </el-table-column>
        <el-table-column prop="className" label="班级" align="center" width="80" :show-overflow-tooltip="true" fixed sortable>
        <!-- <el-table-column prop="className" label="班级" align="center" width="150" :formatter="classNameFormat" :show-overflow-tooltip="true"> -->
        </el-table-column>

        <el-table-column prop="levelName" label="走读/住宿" align="center" width="110" :show-overflow-tooltip="true" >
          <template slot-scope="scope">
            <label v-if="scope.row.levelName">{{scope.row.levelName}}</label>
            <label v-else>走读</label>
          </template>
        </el-table-column>
        <!-- <el-table-column prop="levelName" label="宿舍号" width="120" align="center" :show-overflow-tooltip="true">
        </el-table-column> -->
        <el-table-column prop="status" label="状态"  align="center" :show-overflow-tooltip="true" >
          <template slot-scope="scope">
            <label v-if="scope.row.status==0">无效</label>
            <label v-if="scope.row.status==1">有效</label>

          </template>
        </el-table-column>
        <el-table-column label="启/停用" align="center">
          <template slot-scope="scope">
            <el-switch
              v-model="scope.row.enabled"
              active-value="1"
              inactive-value="0"
              @change="handleEnabledChange(scope.row)"
            />
          </template>
        </el-table-column>

        <el-table-column prop="guardianOfficialOpenId" label="微信公众号" align="center" width="110" :show-overflow-tooltip="true" >
          <template slot-scope="scope">
            <label v-if="scope.row.guardianOfficialOpenId" style="color:#52c41a">已绑定</label>
            <label v-else>未绑定</label>
          </template>
        </el-table-column>

        <!-- <el-table-column prop="studentId" label="学号"  align="center" width="150" :show-overflow-tooltip="true">
        </el-table-column> -->

        <el-table-column prop="gender" label="性别"  align="center" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            <label v-if="scope.row.gender==0">女</label>
            <label v-if="scope.row.gender==1">男</label>
          </template>
        </el-table-column>

        <el-table-column prop="certificateType" label="证件类型" width="120" align="center" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            {{getDictLabel(certificateTypeList,scope.row.certificateType)}}
          </template>
        </el-table-column>
        <el-table-column prop="certificateId" label="证件号" width="180"  align="center" :show-overflow-tooltip="true">
        </el-table-column>

        <el-table-column prop="nativePlace" label="籍贯" align="center" :show-overflow-tooltip="true">
        </el-table-column>

        <el-table-column prop="nation" label="民族"  align="center" :show-overflow-tooltip="true">
        </el-table-column>

        <el-table-column prop="politicalAffiliation" label="政治面貌"  align="center" :show-overflow-tooltip="true">
          <template slot-scope="scope">
            {{getpoliticalAffiliationListVal(scope.row.politicalAffiliation)}}
          </template>
        </el-table-column>

        <el-table-column prop="entranceDate" label="入学年月" width="100"  align="center" :show-overflow-tooltip="true">
            <template slot-scope="scope">
            <span>{{ formatterDate(scope.row.entranceDate,'yyyy-MM-dd') }}</span>
            </template>
        </el-table-column>

        <el-table-column prop="createBy" label="创建用户"  align="center" :show-overflow-tooltip="true">
        </el-table-column>

        <el-table-column fixed="right" label="操作" width="220" align="center" >
          <template slot-scope="scope">
            <el-tooltip class="item" effect="dark" content="宿舍分配" placement="top">
              <el-button type="success" icon="el-icon-office-building" size="mini" circle @click="handleAddDormitory(scope.row)"></el-button>
            </el-tooltip>

            <el-tooltip class="item" effect="dark" content="退宿" placement="top" v-if="scope.row.levelName">
              <el-button type="warning" icon="el-icon-close" size="mini" circle @click="handleRetreat(scope.row)"></el-button>
            </el-tooltip>

            <el-tooltip class="item" effect="dark" content="删除" placement="top">
              <el-button type="danger" icon="el-icon-delete" size="mini" circle @click="del(scope.row)"></el-button>
            </el-tooltip>
            <el-tooltip class="item" effect="dark" content="重置学生密码" placement="top">
              <el-button icon="el-icon-key" size="mini" circle @click="resetPwdHander(scope.row)"></el-button>
            </el-tooltip>
            <el-tooltip class="item" effect="dark" content="重置家长密码" placement="top">
              <el-button icon="el-icon-refresh" size="mini" circle @click="resetParentPwdHander(scope.row)"></el-button>
            </el-tooltip>
          </template>
        </el-table-column>
      </el-table>
      <pagination
        v-show="total > 0"
        :total="total"
        :page.sync="forms.pageNum"
        :limit.sync="forms.pageSize"
        @pagination="originaldata"
      />

      

      <el-dialog title="导入学员信息" :visible.sync="importVisible" width="400px" >
        <el-upload v-loading="importLoading"
          class="upload-demo"
          drag
          :action="upload.url"
          :headers="upload.headers"
          :on-success="handleAvatarSuccess"
          :before-upload="beforeAvatarStudentIndfoUpload"
          :file-list="fileList"
          >
          <i class="el-icon-upload"></i>
          <div class="el-upload__text">将文件拖到此处，或<em>点击上传</em>,建议导入数据不要超过300条，超过300条会导致导入数据变慢</div>
          <div class="el-upload__tip" slot="tip"><el-link type="primary" :href="templateDowloadUrl">模板下载</el-link></div>
        </el-upload>
      </el-dialog>

      

      <el-dialog title="宿舍分配" :visible.sync="dormitoryVisible" width="30%">
        <el-form  :model="bedForm" ref="bedForm" class="demo-form-inline">
          <el-row>
            <el-col :span="6">
              <el-form-item label="姓名">
                {{ bedForm.name }}
              </el-form-item>
            </el-col>
            <el-col :span="6">
              <el-form-item label="班级">
                {{ bedForm.className }}
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="当前宿舍">
                <template>
                  <label v-if="bedForm.levelName">{{ bedForm.levelName }}-{{ bedForm.berthCodeTemp }}号床 </label>
                  <label v-else>走读</label>
                </template>
              </el-form-item>
            </el-col>
          </el-row>
          <el-form-item label="选择宿舍">
            <el-select v-model="bedForm.locationId" clearable filterable placeholder="选择宿舍" @change="getDormitoryBedList">
              <el-option v-for="item in dormitoryList" :key="item.id" :value="item.id" :label="item.levelName">
              </el-option>
            </el-select>
            <el-select v-model="bedForm.id" placeholder="选择床位" clearable filterable>
              <el-option v-for="item in bedList" :key="item.id"   :value="item.id" :label="item.berthCode">
                <span style="float: left">{{ '床位编号：' + item.berthCode }}</span>
                <span style="float: right; color: #8492a6; font-size: 13px" v-if="item.berthType==1">上铺</span>
                <span style="float: right; color: #8492a6; font-size: 13px" v-if="item.berthType==2">下铺</span>
                <span style="float: right; color: #8492a6; font-size: 13px" v-if="item.berthType==3">上铺下桌</span>
              </el-option>
            </el-select>
          </el-form-item>
        </el-form>
        <div slot="footer" class="dialog-footer">
          <el-button type="primary" @click="submitBedUse">确 定</el-button>
          <el-button @click="cancelBed">取 消</el-button>
        </div>
      </el-dialog>

      <el-dialog title="下载素材" :visible.sync="zipDialog">
        <el-link :href="zipPath" target="_blank">下载导出文件</el-link>
      </el-dialog>
    </div>
  </div>
</template>

<script>
// 这里可以导入其他文件（比如：组件，工具js，第三方插件js，json文件，图片文件等等）
// 例如：import 《组件名称》 from '《组件路径》';

import { findSchoolClassPageList} from "@/api/classManage/classInfo";
import { originalData,delt,updateBatchInfo, resetPwd, resetParentPwd, studentsInfoDelete, resetStudentsPwd,
  resetParentsPwd,deviceStudentExcelList,exportStudent,exportDormitoryTemplate,studentRetreat} from "@/api/studentInfo/infoMaintenance/index";
import { getToken } from '@/utils/auth'
import { findBaseSpaceLocationPageList, getDormitoryBerthList,updateDedUse} from "@/api/baseData/siteManagement";


export default {
  // import引入的组件需要注入到对象中才能使用
  components: {},
  data() {
    // 这里存放数据
    return {
      dormitoryUpload:{
        url:process.env.VUE_APP_BASE_API + '/student/info/import/dormitoryExcel',
        headers: {Authorization:"Bearer " + getToken()},
      },
      importLoading:false,
      importImageLoading:false,
      templateDowloadUrl: null,
      pictureTemplateDownLoadUrl: null,
      upload:{
        url:process.env.VUE_APP_BASE_API + '/student/info/import/excel',
        headers: {Authorization:"Bearer " + getToken()},
      },
      imageUpload:{
        url: process.env.VUE_APP_BASE_API + '/student/info/pictureImport/excel',
        headers: {Authorization:"Bearer " + getToken()},
        urlZip:process.env.VUE_APP_BASE_API + '/student/info/pictureImport/zipfile'
      },
      loading:false,
      currentPage: 1,
      total: 0,
      forms: {
        pageNum: 1, //页码
        pageSize: 10, //每页大小
        name: undefined,
        studentId: undefined,
        phone: undefined,
        certificateId: undefined,
        className: undefined,
        dateList:[]
      },
      classOptions: [],
      tableDataList: [],
      multiple:true,
      rowList:[],
      importVisible:false,
      dormitoryVisible:false,
      dormitoryForm:{},
      dormitoryList:[],
      bedList:[],
      bedForm:{},
      fileList:[],
      imageFileList: [],
      politicalAffiliationList:[],
      certificateTypeList:[],
      wordList:[],
      excelTitle:'学生信息',
      json_fields:{
        "学号":"studentId",
        "姓名":"name",
        "手机号":"phone",
        "性别":"gender",
        "证件类型":"certificateType",
        "证件号":"certificateId",
        "入学日期":"entranceDate",
        "班级":"className",
        "籍贯":"nativePlace",
        "政治面貌":"politicalAffiliation",
        "民族":"nation"
      },
      zipPath:null,
      zipDialog:false
    };
  },
  // 监听属性 类似于data概念
  computed: {},
  // 监控data中的数据变化
  watch: {},
  // 方法集合
  methods: {
    dowloadDormitoryTemp(){
      exportDormitoryTemplate().then(resp=>{
        console.log(resp)
        this.fileDownload(resp.data, "宿舍信息表.xlsx");
      })
    },
    exportStudentInfo(){
      exportStudent(this.forms).then(resp=>{
        this.fileDownload(resp.data, "学生信息.xlsx");
      })
    },
    cancelBed(){
      this.dormitoryVisible = false

    },
    submitBedUse(){
      this.$refs["bedForm"].validate(valid => {
        if (valid) {
          updateDedUse(this.bedForm).then(resp=>{
            this.$message({
              message: '提交成功',
              type: 'success'
            });
            this.dormitoryVisible = false
            this.originaldata();
          })
        }
      })

    },
    getDormitoryBedList(val){
      getDormitoryBerthList(val).then(resp=>{
        this.bedList = resp.data
        if(!this.bedList || this.bedList.length==0){
          this.$message({
            message: '该宿舍没有剩余床位',
            type: 'warning'
          });
        }
      })
    },
    getDormitoryList(){
      //宿舍列表
      findBaseSpaceLocationPageList({pageNum:1,pageSize:1000,locationType:6}).then(response => {
        this.dormitoryList = response.data.list;
      });
    },
    handleAddDormitory(row){
      this.dormitoryVisible = true
      this.bedForm={
        useStudentId:row.id,
        name:row.name,
        className:row.className,
        id:null,
        locationId:null,
        levelName:row.levelName,
        berthCodeTemp:row.berthCode
      }
    },
    getDictLabel(list,value){
       for(let i=0;i<list.length;i++){
        if(list[i].dictValue==value){
          return list[i].dictLabel
        }
       }
    },
    getClassList(){
      //查询班级
    findSchoolClassPageList({pageSize:500,pageNum:1,status:1,isGraduation:0}).then(resp=>{
        this.classOptions = resp.data.list
    })
    },
    getpoliticalAffiliationListVal(val){
      for(let i=0;i<this.politicalAffiliationList.length;i++){
        if(val==this.politicalAffiliationList[i].dictValue){
          return this.politicalAffiliationList[i].dictLabel
        }
      }
    },
    //跳转至添加学员信息页面
    Add() {
      this.$router.push("/infoMaintenance/add");
    },
    //初始学生信息
    originaldata() {
      this.loading = true
      if (this.forms.dateList.length > 0) {
        this.forms.modifyPicBeginTime = this.forms.dateList[0];
        this.forms.modifyPicEndTime = this.forms.dateList[1];
      } else {
        this.forms.modifyPicBeginTime = null;
        this.forms.modifyPicEndTime = null;
      }
      originalData(this.forms).then((res) => {
        console.log(res);
        this.tableDataList = res.data.list;
        this.getExportData(JSON.parse(JSON.stringify(res.data.list)))
        this.total = res.data.total;
        this.loading = false
      });
    },
    getExportData(dataList){
      this.wordList=[]
      for(let i=0;i<dataList.length;i++){
        this.wordList[i]=dataList[i]
        this.wordList[i].status = dataList[i].status==0?'无效':'有效'
        this.wordList[i].gender = dataList[i].gender==0?'女':'男'
        console.log(this.getDictLabel(this.certificateTypeList,dataList[i].certificateType))
        this.wordList[i].certificateType = this.getDictLabel(this.certificateTypeList,dataList[i].certificateType)

        this.wordList[i].entranceDate = this.parseTime(dataList[i].entranceDate)
        this.wordList[i].politicalAffiliation = this.getpoliticalAffiliationListVal(dataList[i].politicalAffiliation)
      }
      console.log('this.wordList',this.wordList)
    },
    //根据学生姓名/学号/电话号码/证件号/班级查询学生信息
    findStudentList() {
      this.forms.pageNum = 1;
      this.originaldata();
    },
     /** 重置按钮操作 */
     resetQuery() {
      this.forms = {
        name: undefined,
        studentId: undefined,
        certificateId: undefined,
        phone: undefined,
        className: undefined
      };
      this.forms.pageSize = 10;
      this.findStudentList();
    },
    //修改学生信息
    modify(row){
      this.$router.push({path:"/infoMaintenance/add",query:{id:row.id}});
    },
    // 重置密码
    resetPwdHander(data) {
      this.$confirm("重置【" + data.name + "】密码，请确认", {
        confirmButtonText: "确定",
        cancelButtonText: "取消"
      }).then(() => {
        resetPwd(data).then(response => {
            if (response.code === 200) {
              this.msgSuccess("修改成功，新密码是：" + "12345678");
            } else {
              this.msgError(response.message);
            }
          });

      }).catch(() => {});
    },
    resetParentPwdHander(data){
      this.$confirm("重置【" + data.name + "】家长密码，请确认", {
        confirmButtonText: "确定",
        cancelButtonText: "取消"
      }).then(() => {
        resetParentPwd(data).then(response => {
            if (response.code === 200) {
              this.msgSuccess("修改成功，新密码是：" + "12345678");
            } else {
              this.msgError(response.message);
            }
          });

      }).catch(() => {});
    },
    //删除学生信息
    del(row){
      this.$confirm('确定要删除吗?', "警告", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
                  }).then(() => {
                    delt(row.id).then((res)=>{
                      this.msgSuccess('删除成功');
                      this.findStudentList()
                    });
                  }).catch(function() {

                  });

    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      console.log(selection)
      this.rowList = selection
      this.multiple = !selection.length
      //获取选中的数据作为导出数据
      this.getExportData(JSON.parse(JSON.stringify(selection)))
    },
    batchUpdateStatus(flag){
      let str = '有效'
      if(flag == 0){
        str = '无效'
      }
      this.$confirm('确定要修改为【'+str+'】吗?', "警告", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
      }).then(() => {
        for(let i=0;i<this.rowList.length;i++){
        this.rowList[i].status=flag
        }
        this.loading = true
        updateBatchInfo(this.rowList).then(resp=>{
          this.msgSuccess('修改' +str + "成功");
          this.loading = false
          this.originaldata();
        })
      }).catch(function() {

      });
    },
    importData(){
      //打开导入页面
      this.importVisible = true
      this.fileList = []

    },

    handleDormitorySuccess(res, file){
      if(res.code==200){
        this.$message({ message: '导入成功', type: 'success'});
        this.importLoading = false
        this.findStudentList();
      }else{
        this.$message.error(res.message);
        this.importLoading = false
      }
      this.fileList=[]
    },
    beforeDormitoryUpload(file){
      this.importLoading = true
      console.log(file.name.lastIndexOf('.xlsx'))
      if(file.name.lastIndexOf('.xlsx')<0 && file.name.lastIndexOf('.XLSX')<0){
        this.$message({
          message: '上传文件只能是.xlsx文件',
          type: 'warning'
        });
        return false
      }
      console.log(file,'beforefile')

    },
    handleAvatarSuccess(res, file){
      if(res.code==200){
        this.$message({ message: '导入成功', type: 'success'});
        this.importLoading = false
        this.importVisible = false
        this.findStudentList();
      }else{
        this.$message.error(res.message);
        this.importLoading = false
      }
      this.fileList=[]

    },
    beforeAvatarUpload(file){
      this.importLoading = true
      console.log(file.name.lastIndexOf('.zip'))
      if(file.name.lastIndexOf('.zip')<0 && file.name.lastIndexOf('.ZIP')<0){
        this.$message({
          message: '上传文件只能是.zip压缩文件',
          type: 'warning'
        });
        return false
      }
      console.log(file,'beforefile')

    },
    beforeAvatarStudentIndfoUpload(file) {
      this.importLoading = true
      console.log(file.name.lastIndexOf('.xlsx'))
      if(file.name.lastIndexOf('.xlsx')<0 && file.name.lastIndexOf('.XLSX')<0){
        this.$message({
          message: '上传文件只能是.xlsx文件',
          type: 'warning'
        });
        return false
      }
      console.log(file,'beforefile')
    },
    // 批量删除按钮操作
    handleDeleteBatch(){
        this.$confirm('是否确认删除选择的数据项?', "警告", {
                  confirmButtonText: "确定",
                  cancelButtonText: "取消",
                  type: "warning"
                }).then(() => {
                  studentsInfoDelete(this.rowList).then(resp=>{
                        this.msgSuccess("删除成功");
                        this.loading = false
                        this.originaldata();
                    })

                }).catch(function() {});
    },
    batchResetStudentsPwdHander(){
      this.$confirm('是否确认重置?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        resetStudentsPwd(this.rowList).then(resp=>{
          this.msgSuccess("重置成功");
          this.loading = false;
          this.originaldata();
        })
      }).catch(function() {});
    },
    batchResetParentPwdHander(){
      this.$confirm('是否确认重置?', "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning"
      }).then(() => {
        resetParentsPwd(this.rowList).then(resp => {
          this.msgSuccess("重置成功");
          this.loading = false;
          this.originaldata();
        })
      }).catch(function() {});
    },
    // 学员状态修改
    handleEnabledChange(row) {
      let text = row.enabled === "1" ? "启用" : "停用";
      this.$confirm(
        '确认要将学生【"' + row.name + '"】设置为?' + text,
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning"
        }
      )
        .then(function() {
          var array = [row]
          // console.log(row.enabled)
          return updateBatchInfo(array)
        })
        .then(() => {
          this.msgSuccess(text + "成功");
          this.originaldata();
        })
        .catch(function() {
          row.enabled = row.enabled === "0" ? "1" : "0";
        });
    },
    batchUpdateEnable(flag){
      let str = '启用'
      if(flag == 0){
        str = '停用'
      }
      this.$confirm('确定要修改为【'+str+'】吗?', "警告", {
                    confirmButtonText: "确定",
                    cancelButtonText: "取消",
                    type: "warning"
      }).then(() => {
        for(let i=0;i<this.rowList.length;i++){
          this.rowList[i].enabled=flag
        }
        this.loading = true
        updateBatchInfo(this.rowList).then(resp=>{
          this.msgSuccess('修改' + str + "成功");
          this.loading = false
          this.originaldata();
        })
      }).catch(function() {

      });
    },
    deviceStudentExcel(){
      this.loading = true
      deviceStudentExcelList(this.forms).then(response => {
        console.log(response.data)
        this.zipPath = process.env.VUE_APP_BASE_API +"/student/picture/"+ response.data.data
        this.zipDialog = true
        this.loading=false
        // this.fileDownload(response.data, "学生信息.xlsx");
      }).catch((e)=>{
        this.loading=false
      });
    },

    formatterDate(thistime, fmt) {
      if(!thistime){
        return ''
      }
      let $this = new Date(thistime)
      let o = {
        'M+': $this.getMonth() + 1,
        'd+': $this.getDate(),
        'h+': $this.getHours(),
        'm+': $this.getMinutes(),
        's+': $this.getSeconds(),
        'q+': Math.floor(($this.getMonth() + 3) / 3),
        'S': $this.getMilliseconds()
      }
      if (/(y+)/.test(fmt)) {
        fmt = fmt.replace(RegExp.$1, ($this.getFullYear() + '').substr(4 - RegExp.$1.length))
      }
      for (var k in o) {
        if (new RegExp('(' + k + ')').test(fmt)) {
          fmt = fmt.replace(RegExp.$1, (RegExp.$1.length === 1) ? (o[k]) : (('00' + o[k]).substr(('' + o[k]).length)))
        }
      }
      return fmt
    },

    //退宿
    handleRetreat(row){
      console.log(row)
      let obj =
      {
        id:row.berthId,
        useStudentId:row.id
      }
      this.$confirm('【' + row.name + '】退宿, 是否继续?', '提示', {
        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
          this.loading = true
          studentRetreat(obj).then(resp => {
            this.msgSuccess('【' + row.name + "】退宿成功");
            this.loading = false
            this.originaldata();
          });
      }).catch(() => {
        this.$message({
          type: 'info',
          message: '已取消退宿'
        });
      });
    }

  },
  // 生命周期 - 创建完成（可以访问当前this实例）
  created() {

    this.templateDowloadUrl = process.env.VUE_APP_BASE_API + "/school/file/student.xlsx"
    this.pictureTemplateDownLoadUrl = process.env.VUE_APP_BASE_API + '/school/file/student_picture.zip'
    this.dormitoryTemplateDowloadUrl = process.env.VUE_APP_BASE_API + '/student/info/import/dormitoryExcelTemplate'

    this.getDicts("political_affiliation").then(response => {
        this.politicalAffiliationList = response.data;

    });
    this.getDicts("certificate_type").then(response => {
        this.certificateTypeList = response.data;
    });
    this.getClassList();
    this.originaldata();
    this.getDormitoryList();
  },
  // 生命周期 - 挂载完成（可以访问DOM元素）
  mounted() {},
  beforeCreate() {}, // 生命周期 - 创建之前
  beforeMount() {}, // 生命周期 - 挂载之前
  beforeUpdate() {}, // 生命周期 - 更新之前
  updated() {}, // 生命周期 - 更新之后
  beforeDestroy() {}, // 生命周期 - 销毁之前
  destroyed() {}, // 生命周期 - 销毁完成
  activated() {}, // 如果页面有keep-alive缓存功能，这个函数会触发
};
</script>
<style lang='scss' scoped>
// @import url(); 引入公共css类
.button_add {
  margin-top: 2rem;
  margin-left: 2rem;
}
.el-button--warning.is-plain{
  padding: 7px 15px;
}
.contenr {
  margin: 20px;
}
</style>
